#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "CommonHelper/CommonHelper.h"

MainWindow::MainWindow(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::MainWindow){
    ui->setupUi(this);

    this->setWindowFlags(Qt::FramelessWindowHint);

    CommonHelper::loadStyleSheet("D:/QTProject/SnailIOTMonitoring/resources/img.css");


    m_pHead = new Head;
    m_pMiddle = new Middle;
    m_pTail = new Tail;
    m_pForget = new Forget;
    m_pAdminWindow = new AdminWindow;
    m_pUserWindow = new UserWindow;
    m_pEnroll = new Enroll;

    ui->head->addWidget(m_pHead);
    ui->tail->addWidget(m_pTail);
    ui->middle->addWidget(m_pMiddle);

    //头的三个按键
    connect(m_pHead, &Head::closesignal, this, &MainWindow::close);
    connect(m_pHead, &Head::maxsignal, this, &MainWindow::toggleMinimize);
    connect(m_pHead, &Head::minsignal, this, &MainWindow::showMinimized);

    m_pStackedLayout = new QStackedLayout(ui->middle);
    m_pStackedLayout->addWidget(m_pMiddle);
    m_pStackedLayout->addWidget(m_pForget);
    m_pStackedLayout->addWidget(m_pAdminWindow);
    m_pStackedLayout->addWidget(m_pUserWindow);
    m_pStackedLayout->addWidget(m_pEnroll);

    connect(m_pMiddle, &Middle::LoginSucceed, m_pStackedLayout, &QStackedLayout::setCurrentIndex);
    connect(m_pMiddle, &Middle::Enroll, m_pStackedLayout, &QStackedLayout::setCurrentIndex);
    connect(m_pMiddle, &Middle::Forget, m_pStackedLayout, &QStackedLayout::setCurrentIndex);
    connect(m_pEnroll, &Enroll::Login, m_pStackedLayout, &QStackedLayout::setCurrentIndex);
    connect(m_pForget, &Forget::Login, m_pStackedLayout, &QStackedLayout::setCurrentIndex);

}

MainWindow::~MainWindow(){
    delete ui;
}

